package com.qiall.boot.fileservice.trans;

import com.qiall.boot.fileability.request.FileInfoDTO;
import com.qiall.boot.fileservice.data.eitity.DirectInfo;
import com.qiall.boot.fileservice.data.eitity.FileInfo;
import com.qiall.boot.fileservice.data.eitity.enums.UploadStatusEnum;
import com.qiall.boot.fileservice.data.mapper.DirectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <h3>qiall-framework</h3>
 *
 * @author panziye
 * @description <p>file data trans</p>
 * @date 2022-10-14 20:38
 **/
@Service
public class FileDataTrans {
    @Autowired
    private DirectMapper directMapper;

    public FileInfoDTO trans(FileInfo fileInfo) {
        FileInfoDTO fileInfoDTO = new FileInfoDTO();
        fileInfoDTO.setId(fileInfo.getId());
        fileInfoDTO.setFileName(fileInfo.getFileName());
        fileInfoDTO.setContextType(fileInfo.getContextType());
        fileInfoDTO.setFromType(fileInfo.getFromType());
        fileInfoDTO.setFromId(fileInfo.getFromId());
        fileInfoDTO.setFileSize(fileInfo.getFileSize());
        fileInfoDTO.setUploaderId(fileInfo.getUploaderId());
        fileInfoDTO.setUploadStatus(UploadStatusEnum.ofCode(fileInfo.getUploadStatus()).getDesc());
        fileInfoDTO.setDirectId(fileInfo.getDirectId());
        DirectInfo directInfo = directMapper.select(fileInfo.getDirectId());
        if(directInfo!=null){
            fileInfoDTO.setDirectName(directInfo.getDirectName());
        }
        fileInfoDTO.setCreateTime(fileInfo.getCreateTime());
        return fileInfoDTO;
    }
}
